﻿using System;

using octalforty.Componento.Core.ApplicationServices.Impl;

namespace octalforty.Componento.Core.ApplicationServices
{
    public class MetadirectoryManagerService
    {
        public virtual void Initialize(string basePath, bool probe)
        {
            var path = GetProbedPath(probe, basePath);

            var metadirectory = new Metadirectory(path);
            metadirectory.Initialize();
        }

        public void AddRepository(string basePath, bool probe, string alias, string uri)
        {
            var path = GetProbedPath(probe, basePath);

            var metadirectory = new Metadirectory(path);
            metadirectory.AddRepository(alias, uri);
        }

        public Uri GetRepositoryUri(string basePath, bool probe, string alias)
        {
            var path = GetProbedPath(probe, basePath);

            var metadirectory = new Metadirectory(path);
            return metadirectory.GetRepositoryUri(alias);
        }

        public string GetProbedPath(bool probe, string basePath)
        {
            return probe ?
                Metadirectory.Probe(basePath) :
                basePath;
        }
    }
}
